{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#####################################\n",
    "##########  训练landmarks  ##########"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 906,
     "status": "ok",
     "timestamp": 1692409208454,
     "user": {
      "displayName": "rui lu",
      "userId": "15695518765939055507"
     },
     "user_tz": -480
    },
    "id": "pj8JGV0t3oEU",
    "outputId": "70318998-c0aa-4727-e35b-a56ae4e9b253"
   },
   "outputs": [],
   "source": [
    "#@title 一、数据准备\n",
    "# # 1、上传数据集\n",
    "# cd LangXin\n",
    "unzip data.zip\n",
    "# rm -rf data.zip\n",
    "\n",
    "# # 2、将视频转化为16000赫兹，单声道\n",
    "python 16000.py\n",
    "\n",
    "# # 3、将视频切割成2-5秒一段\n",
    "python split_video.py\n",
    "\n",
    "# # 4、生成 train.txt 、test.txt文档\n",
    "python  sample.py\n",
    "\n",
    "# # 5、将train.txt 、test.txt按照顺序排列\n",
    "python  123456.py\n",
    "\n",
    "# # 6、将视频转化为16000赫兹，单声道\n",
    "python 16000-more.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "iK8K52Fi5Zwy"
   },
   "outputs": [],
   "source": [
    "#@title 二、训练数据预处理\n",
    "cd preprocess\n",
    "# cd preprocess\n",
    "# # 1、音频处理\n",
    "python preprocess_audio.py --data_root ../data --out_root ../data_audio\n",
    "\n",
    "# # 2、 视频处理\n",
    "# # 确定好人脸 pading 像素值,默认是5。\n",
    "cd  preprocess\n",
    "python preprocess_video.py --dataset_video_root ../data --output_sketch_root  ../data_sketch --output_face_root  ../data_face --output_landmark_root  ../data_landmarks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "EnQKsris5Z2u",
    "outputId": "96f2d637-4450-406a-cd11-0028e33a0dcf"
   },
   "outputs": [],
   "source": [
    "# #@title 三、训练数据预处理\n",
    "# # 1、训练landmarks\n",
    "# cd LangXin\n",
    "python train_landmarks_generator.py --pre_audio_root  ./data_audio  --landmarks_root ./data_landmarks  \n",
    "python train_landmarks_generator.py --pre_audio_root  ./data_audio  --landmarks_root ./data_landmarks   --load_checkpoint ./checkpoints/landmark_generation/Pro_landmarkT5_d512_fe1024_lay4_head4/landmarkT5_d512_fe1024_lay4_head4_epoch_2426_checkpoint_step001150000.pth \n",
    "\n",
    "# # 如果报错的话就将\n",
    "# # shuffle=True, 改成\n",
    "# # shuffle=False,\n",
    "# ########################\n",
    "# # 如果再报错，将\n",
    "# # num_workers = 4\n",
    "# # batch_size =12  # # 512"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "5f8R5QaS5Z5N"
   },
   "outputs": [],
   "source": [
    "# # 2、训练renderer渲染器\n",
    "# cd LangXin\n",
    "python train_video_renderer.py --sketch_root ./data_sketch --face_img_root ./data_face  --audio_root ./data_audio\n",
    "\n",
    "\n",
    "# # 如果报错的话就将\n",
    "# # shuffle=True, 改成\n",
    "# # shuffle=False,\n",
    "# ########################\n",
    "# # 如果再报错，将\n",
    "# # num_workers = 4\n",
    "# # batch_size =12  # # 512"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 10717,
     "status": "ok",
     "timestamp": 1692016950239,
     "user": {
      "displayName": "rui lu",
      "userId": "15695518765939055507"
     },
     "user_tz": -480
    },
    "id": "cKztai6i1nr7",
    "outputId": "6badb845-2f44-4ceb-97ce-f34f622d6a42"
   },
   "outputs": [],
   "source": [
    "#@title 四、进行推理准备，将自己训练好的权重复制并放在下面路径\n",
    "cp XXXXXXXXX     ./test/checkpoints\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "executionInfo": {
     "elapsed": 256141,
     "status": "ok",
     "timestamp": 1692020908590,
     "user": {
      "displayName": "rui lu",
      "userId": "15695518765939055507"
     },
     "user_tz": -480
    },
    "id": "d6cKLTe8Nsna",
    "outputId": "83084fc4-d86d-4b4f-fe3f-cbb9c075ae77"
   },
   "outputs": [],
   "source": [
    "#@title 五  运行训练后的模型推理 \n",
    "# 改代码inference_single.py  line 34 fa = face_alignment.FaceAlignment(face_alignment.LandmarksType.TWO_D, flip_input=False, device='cuda')\n",
    "cd /content/LangXin\n",
    "python inference_single.py --input ./test/555.mp4  --audio ./test/555.wav  --landmark_gen_checkpoint_path  ./test/new-checkpoints/new-landmarkT5_d512_fe1024_lay4_head4_epoch_17000_checkpoint_step000850000.pth   --renderer_checkpoint_path  ./test/new-checkpoints/new-renderer_T1_ref_N3_epoch_661_checkpoint_step000354000.pth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 查看文件夹下面， 每个子文件夹下面的文件数量\n",
    "for d in */ ; do echo \"$d\"; find \"$d\" -maxdepth 1 -type f | wc -l; done\n",
    "\n",
    "# 查看文件大小\n",
    "du -sh 300\n",
    "\n",
    "#  查看音频采样\n",
    "ffmpeg -i audio.wav\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 跨区域拷贝数据\n",
    "# 拷贝到那个区的项目\n",
    "ssh -p 17302 root@connect.westb.seetacloud.com\n",
    "# 从此项目拷贝到目标项目中\n",
    "scp -rP 17302 /root/landmarkT5_d512_fe1024_lay4_head4_epoch_714_checkpoint_step000005000.pth  root@connect.westb.seetacloud.com:/root/autodl-tmp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ssh -p 44125 root@connect.westb.seetacloud.com\n",
    "scp -rP 44125 /root/autodl-tmp/300-000   root@connect.westb.seetacloud.com:/root/autodl-tmp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# tensorboard显示loss\n",
    "tensorboard --port 7860 --logdir /root/autodl-tmp/LangXin/tensorboard_runs/Project_landmarkT5_d512_fe1024_lay4_head4"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "authorship_tag": "ABX9TyPUkKcxt/N0eB/pyDWg88Uu",
   "provenance": [
    {
     "file_id": "1bY0Kw2oWWrpKS6ne-TBCbW-iFyXIrRR7",
     "timestamp": 1680665453952
    }
   ]
  },
  "gpuClass": "standard",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
